home *** CD-ROM | disk | FTP | other *** search
/ Champak 25 / Volume 25 - JOGO DISK .iso / Games / the_jewel_hunter.swf / scripts / Blocker.as < prev    next >
Text File  |  2006-06-13  |  6KB  |  230 lines

  1. classBlock = function()
  2. {
  3.    this.init();
  4. };
  5. classBlock.prototype = new MovieClip();
  6. Object.registerClass("Blocker",classBlock);
  7. classBlock.prototype.init = function()
  8. {
  9.    var _loc1_ = this;
  10.    Game.block = _loc1_;
  11.    _loc1_.createEmptyMovieClip("holder",10);
  12.    _loc1_.available = new Array(8);
  13.    _loc1_.block_type = new Array("Cactus","Rock");
  14.    _loc1_.lastCreate = 0;
  15.    _loc1_.onEnterFrame = _loc1_.movement;
  16. };
  17. classBlock.prototype.movement = function()
  18. {
  19.    var _loc1_ = this;
  20.    if(Game.start)
  21.    {
  22.       if(_loc1_.count >= 60)
  23.       {
  24.          if(_loc1_.depth > 65530)
  25.          {
  26.             _loc1_.depth = 0;
  27.          }
  28.          _loc1_.itemcount = _loc1_.itemcount + 1;
  29.          if(_loc1_.itemcount >= 8)
  30.          {
  31.             _loc1_.createBonus();
  32.          }
  33.          var _loc2_ = random(_loc1_.available.length - _loc1_.lastCreate);
  34.          _loc1_.create(_loc2_);
  35.          _loc1_.count = 0;
  36.       }
  37.       else
  38.       {
  39.          _loc1_.count += Game.speed;
  40.       }
  41.       _loc1_.update();
  42.    }
  43. };
  44. classBlock.prototype.create = function(count)
  45. {
  46.    var _loc1_ = this;
  47.    var toCreate = Math.min(Math.min(5,Game.level),count);
  48.    var created = toCreate;
  49.    _loc1_.lastCreate = 0;
  50.    do
  51.    {
  52.       var _loc3_ = random(_loc1_.available.length - 1);
  53.       if(!_loc1_.available[_loc3_])
  54.       {
  55.          created--;
  56.          _loc1_.available[_loc3_] = true;
  57.          _loc1_.lastCreate = _loc1_.lastCreate + 1;
  58.          _loc1_.depth = _loc1_.depth + 1;
  59.          var type = random(_loc1_.block_type.length);
  60.          var _loc2_ = _loc1_.holder.attachMovie(_loc1_.block_type[type],_loc1_.block_type[type] + _loc1_.depth,_loc1_.depth);
  61.          _loc2_.gotoAndStop(random(_loc2_._totalframes) + 1);
  62.          _loc2_._x = _loc3_ * 47.5 + 23.75 + random(10) - 5;
  63.          _loc2_._y = -30 + random(10) - 5;
  64.          _loc2_._xscale = _loc2_._yscale = random(30) + 80;
  65.          _loc2_.pos = _loc3_;
  66.          _loc2_.type = 1;
  67.       }
  68.       toCreate--;
  69.    }
  70.    while(toCreate > 0);
  71.    
  72.    if(created > 0)
  73.    {
  74.       if(_loc1_.snakeCount < Game.level && _loc1_.snakeCount < 3)
  75.       {
  76.          _loc1_.createSnake();
  77.       }
  78.    }
  79. };
  80. classBlock.prototype.createSnake = function()
  81. {
  82.    var _loc2_ = this;
  83.    if(random(100) < 80)
  84.    {
  85.       _loc2_.createBike();
  86.    }
  87.    else
  88.    {
  89.       var _loc3_ = random(350);
  90.       var dir = random(2);
  91.       _loc2_.snakeCount += 1;
  92.       _loc2_.depth = _loc2_.depth + 1;
  93.       var _loc1_ = _loc2_.holder.attachMovie("snake","snake" + _loc2_.depth,_loc2_.depth);
  94.       _loc1_.type = 2;
  95.       if(dir == 0)
  96.       {
  97.          _loc1_.dir = - (random(Math.min(5,Game.level)) + 1);
  98.          _loc1_._x = 400;
  99.          _loc1_._xscale = -100;
  100.       }
  101.       else
  102.       {
  103.          _loc1_.dir = random(Math.min(5,Game.level)) + 1;
  104.          _loc1_._x = -20;
  105.       }
  106.       _loc1_._y = _loc3_;
  107.    }
  108. };
  109. classBlock.prototype.createBike = function()
  110. {
  111.    var _loc1_ = this;
  112.    if(_loc1_.bikeCount < Math.min(5,Game.level))
  113.    {
  114.       var _loc3_ = random(_loc1_.available.length - 1);
  115.       if(!_loc1_.available[_loc3_])
  116.       {
  117.          _loc1_.bikeCount = _loc1_.bikeCount + 1;
  118.          _loc1_.depth = _loc1_.depth + 1;
  119.          var _loc2_ = _loc1_.holder.attachMovie("Bike","Bike" + _loc1_.depth,_loc1_.depth);
  120.          _loc2_._x = _loc3_ * 47.5 + 23.75;
  121.          _loc2_._y = -30;
  122.          _loc2_.start = false;
  123.          _loc2_.xspeed = _loc2_.yspeed = Math.min(5,random(Game.level) + 1);
  124.          _loc2_.type = 3;
  125.       }
  126.    }
  127. };
  128. classBlock.prototype.createBonus = function(count)
  129. {
  130.    var _loc1_ = this;
  131.    if(_loc1_.itemdir)
  132.    {
  133.       var _loc3_ = random(4);
  134.    }
  135.    else
  136.    {
  137.       _loc3_ = random(4) + 4;
  138.    }
  139.    _loc1_.itemdir = !_loc1_.itemdir;
  140.    if(!_loc1_.available[_loc3_])
  141.    {
  142.       _loc1_.available[_loc3_] = true;
  143.       _loc1_.lastCreate = _loc1_.lastCreate + 1;
  144.       _loc1_.depth = _loc1_.depth + 1;
  145.       _loc1_.itemcount = 0;
  146.       var type;
  147.       var bonus;
  148.       if(random(100) > 90)
  149.       {
  150.          type = "bonus";
  151.          bonus = 100;
  152.       }
  153.       else
  154.       {
  155.          type = "items";
  156.          bonus = 25;
  157.       }
  158.       var _loc2_ = _loc1_.holder.attachMovie(type,type + _loc1_.depth,_loc1_.depth);
  159.       _loc2_.gotoAndStop(random(_loc2_._totalframes) + 1);
  160.       _loc2_._x = _loc3_ * 47.5 + 23.75;
  161.       _loc2_._y = -30;
  162.       _loc2_.pos = _loc3_;
  163.       _loc2_.type = 0;
  164.       _loc2_.bonus = bonus;
  165.    }
  166. };
  167. classBlock.prototype.update = function()
  168. {
  169.    var _loc2_ = this;
  170.    for(var _loc3_ in _loc2_.holder)
  171.    {
  172.       var _loc1_ = _loc2_.holder[_loc3_];
  173.       _loc1_._y += Game.speed;
  174.       if(_loc1_.type == 0)
  175.       {
  176.          if(_loc1_.pos != undefined)
  177.          {
  178.             if(_loc1_._y > 200)
  179.             {
  180.                _loc2_.available[_loc1_.pos] = false;
  181.                delete _loc1_.pos;
  182.             }
  183.          }
  184.       }
  185.       else if(_loc1_.type == 1)
  186.       {
  187.          if(_loc1_.pos != undefined)
  188.          {
  189.             if(_loc1_._y > 200)
  190.             {
  191.                _loc2_.available[_loc1_.pos] = false;
  192.                delete _loc1_.pos;
  193.             }
  194.          }
  195.       }
  196.       else if(_loc1_.type == 2)
  197.       {
  198.          _loc1_._x += _loc1_.dir;
  199.       }
  200.       else if(_loc1_.type == 3)
  201.       {
  202.          _loc1_.smoke();
  203.          if(!_loc1_.start)
  204.          {
  205.             _loc1_._y -= 1;
  206.             if(_loc1_._y > 170)
  207.             {
  208.                _loc1_.start = true;
  209.             }
  210.          }
  211.          else
  212.          {
  213.             _loc1_.update();
  214.          }
  215.       }
  216.       if(_loc1_._y > 580)
  217.       {
  218.          if(_loc1_.type == 2)
  219.          {
  220.             _loc2_.snakeCount -= 1;
  221.          }
  222.          else if(_loc1_.type == 3)
  223.          {
  224.             _loc2_.bikeCount -= 1;
  225.          }
  226.          removeMovieClip(_loc1_);
  227.       }
  228.    }
  229. };
  230.